package com.ivt.dao;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;

import com.ivt.model.Classes;
import com.ivt.utils.enums.AuditStatus;

public interface ClassesDao extends JpaRepository<Classes, Long> {

	@QueryHints({ @QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true") })
	@Query(value = "SELECT  count(c) FROM  Classes c where c.name = ?1")
	public long existsByName(String name);

	@QueryHints({ @QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true") })
	@Query("SELECT  count(c) FROM  Classes c where c.name = ?1 and c.classesId <> ?2")
	public long existsByNameAndId(String name, Long classesId);

	@QueryHints({ @QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true") })
	@Query("SELECT c FROM  Classes c where c.status = ?1 ")
	public List<Classes> findByStatus(AuditStatus status);

}
